How to Apply Security to an Item through the Sitecore API
Prev Next Author: Alexander Tsvirchkov
Posted: 3/29/2006 1:28:28 PM
Sitecore version: tested with 5.1.1.11
See the code below:
//Get /home node
Database db = Sitecore.Configuration.Factory.GetDatabase("master");
Item itm = db.Items["/sitecore/content/home"];
// Domain: sitecore
Domain domain = Factory.GetDomain("sitecore");
//Read and Write permissions
ItemRights rights;
rights = ItemRights.AllowRead | ItemRights.AllowWrite;
//User: editor
UserItem userItem = domain.GetUser("editor");
//Set permission: editor can read and write "/sitecore/content/home" node
itm.Editing.BeginEdit();
itm.SecurityField.SetRights(domain, userItem.ID , rights);
itm.Editing.EndEdit();
Prev Next